package main

import (
	"net/http"
	"webinter/myalert"
	"webinter/mytool"
	"webinter/zbxinter"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.Use(Auth())
	r.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "hello gin zabbix webhook")
	})
	r.POST("/zbxinter/Inter", zbxinter.Inter)
	r.GET("/myalert/MyWxVerify", myalert.MyWxVerify)
	r.Run(":" + mytool.AllConf.Port)
}

func Auth() gin.HandlerFunc {
	return func(c *gin.Context) {
		requesttoken := c.Query("token")
		if requesttoken != mytool.AllConf.Token {
			c.String(403, "not auth")
			c.Abort()
		} else {
			c.Next()
		}
	}
}
